package es.usal.proyecto.Model;

import java.util.ArrayList;
import java.util.Observable;

public class LanguagesModel extends Observable{

	private ArrayList<Language> langs = new ArrayList<Language>();
	
	private static LanguagesModel instance = null;
    private LanguagesModel() { }
    public static synchronized LanguagesModel getInstance() {
        if (instance == null) {
            instance = new LanguagesModel();
        }
        return instance;
    }
    
    public void addLanguage (String name, boolean available, String fileName){
		langs.add(new Language(name, available, fileName));
    }
    
    public Language getLang(String name){
    	for (Language lang : langs) {
			if(lang.getLangName().compareTo(name) == 0)
				return lang;
		}
    	return null;
    }
    
    public Language getLangByIndex(int index){
    	return langs.get(index);
    }
    
    public void modifyLanguage (int langIndex, boolean available, String fileName){
    	Language lang = langs.get(langIndex);
    	lang.setAvailable(available);
    	lang.setFileName(fileName);
    	lang.setInstalling(false);
		this.setChanged();
		this.notifyObservers();
    }
    
    public void installingLanguage(int langIndex){
    	Language lang = langs.get(langIndex);
    	lang.setInstalling(true);
    	this.setChanged();
    	this.notifyObservers();
    }
    
    public boolean isInstallingLanguage (int langIndex){
    	Language lang = langs.get(langIndex);
    	return lang.isInstalling();
    }
}
